const jwt = require('jsonwebtoken')
const { SERCET_KEY } = require('../app/config')
class AuthController {
  async login (ctx, next) {
    const { id, name } = ctx.user
    const token = jwt.sign({ id, name }, SERCET_KEY, { 
      expiresIn: 1000 * 60 * 60 * 24 * 30 // 一个月
     })
     // 解密的token
    /* const authorization = ctx.headers.authorization
    const token = authorization.replace('Bearer ', '') 
    const result = jwt.verify(token, SERCET_KEY)
    ctx.body = result */
    ctx.body = { id, name, token }
  }
  async success (ctx, next) {
    ctx.body = '授权成功~'
  }
}

module.exports = new AuthController()